import * as types from '../actionTypes'
import store from '@/store'

export const getUserInfo = token => {
  return new Promise((resolve, reject) => {
    const data = {
      userInfo: {
        admin: {
          id: 'admin',
          role: 'admin',
          name: '海洋二号',
          avatar: 'http://himg.bdimg.com/sys/portrait/item/f8f66a696b657974616e671b00.jpg',
          description: '拥有系统内所有菜单和路由权限',
        }
      }
    }
      
    store.dispatch(setUserInfo(data.userInfo.admin))
    resolve(data)
  })
}

export const setUserToken = token => {
  return {
    type: types.USER_SET_USER_TOKEN,
    token
  }
}

export const setUserInfo = userInfo => {
  return {
    type: types.USER_SET_USER_INFO,
    ...userInfo,
  }
}

export const resetUser = () => {
  return {
    type: types.USER_RESET_USER
  }
}
